package com.cq.hd.product.controller;

import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.product.api.TbSearchRecordApi;
import com.cq.hd.product.api.dto.SearchDto;
import com.cq.hd.product.api.dto.SearchRecordPageDto;
import com.cq.hd.product.api.vo.SearchRecordPageVo;
import com.cq.hd.product.service.TbSearchRecordService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 历史搜索表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-11-23
 */
@RestController
public class TbSearchRecordController implements TbSearchRecordApi {

    @Autowired
    private TbSearchRecordService searchRecordService;

    @ApiOperation(value = "历史搜索列表")
    @ApiImplicitParam(name = "searchRecordPageDto", value = "实体", paramType = "query", dataType = "SearchRecordPageDto")
    @ApiResponse(response = SearchRecordPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<SearchRecordPageVo>> pageSearchRecord(SearchRecordPageDto searchRecordPageDto) {
        return ResultGenerator.success(searchRecordService.pageSearchRecord(searchRecordPageDto));
    }

    @ApiOperation(value = "搜索")
    @ApiImplicitParam(name = "searchDto", value = "实体", paramType = "query", dataType = "SearchDto")
    @Override
    public Result<Object> search(@RequestBody SearchDto searchDto) {
        return ResultGenerator.success(searchRecordService.search(searchDto));
    }

    @ApiOperation(value = "删除历史搜索词")
    @Override
    public Result<Boolean> deleteSearchRecord(Long userId, Long id) {
        return ResultGenerator.success(searchRecordService.deleteSearchRecord(userId, id));
    }
}
